package main

import (
	"blog/app/http/middlewares"
	"blog/bootstrap"
	"blog/config"
	c "blog/pkg/config"
	"database/sql"
	"embed"
	"net/http"

	_ "github.com/go-sql-driver/mysql"
	"github.com/gorilla/mux"
)

var router *mux.Router
var db *sql.DB

//go:embed resources/views/articles/*
//go:embed resources/views/auth/*
//go:embed resources/views/categories
//go:embed resources/views/layouts/*
var tplFS embed.FS

//go:embed public/*
var staticFS embed.FS

func init() {
	config.Initialize()
}

func main() {
	//初始化sql
	bootstrap.SetupDB()

	//初始化模板
	bootstrap.SetupTemplate(tplFS)

	//初始化路由绑定
	router = bootstrap.SetupRoute(staticFS)

	http.ListenAndServe(":"+c.GetString("app.port"), middlewares.RemoveTrailingSlash(router))
}
